#ifndef __SYSTEM_H_
#define __SYSTEM_H_

/****************************************************************
DEFINE THE DATATYPE
****************************************************************/
typedef unsigned int                 BOOLEAN;
typedef unsigned char               INT8U; //Unsigned 8 bit quantity
typedef signed char                  INT8S; //Signed 8 bit quantity
typedef unsigned short              INT16U;
typedef signed short                INT16S;
typedef unsigned int                INT32U; // Unsigned 32 bit quantity
typedef signed int                   INT32S; // Signed 32 bit quantity
typedef unsigned long              INT32LU; // Unsigned 32 bit quantity
typedef signed long                 INT32LS; // Signed 32 bit quantity
typedef unsigned int                mem_ptr_t;
typedef volatile INT8U             vINT8U;
typedef volatile INT16U           vINT16U;
typedef volatile INT32U           vINT32U;
typedef  void (*VFUNC)(void);

#define HIGHBYTE(x)             (INT8U)((x)>>8)
#define LOWBYTE(x)              (INT8U)((x)&0x00ff)

#define HIGHWORD(x)             (INT16U)((x)>>16)
#define LOWWORD(x)              (INT16U)((x)&0x0000ffff)
#define ABS(a,b)                    (((a)>(b))?((a)-(b)):((b)-(a)))
#define UN_16U(a,b)              (INT16U)((((INT16U)a) << 8) + (INT16U)b)
#define UN_32U(a,b,c,d)     (INT32U)((((INT32U)a) << 24) + (((INT32U)b) << 16) + (((INT32U)c) << 8) + (INT32U)d)
#define SEMIHIGH_BYTE(X)    ((X & 0x00ff) >> 4)
#define SEMILOW_BYTE(X)     (X & 0x0f)

#define OFFSET(structure, member) /* byte offset of member in structure*/\
        ((int) &(((structure *) 0) -> member))
#define MEMBER_SIZE(structure, member) /* size of a member of a structure */\
        (sizeof (((structure *) 0) -> member))
#define NELEMENTS(array) /* number of elements in an array */ \
        (sizeof (array) / sizeof ((array) [0]))


#define _CR                   0x0D
#define _LF                    0x0A
//#define CTRL_Z      0x1A
#define ESC                   0x1B
#define _SUCCESS         0
#define _FAILURE          1
#define _OVERTIME       2
#define _ABANDON        3

typedef union {
    INT16U word;
    struct {
        INT8U low;
        INT8U high;
    } bytes;
}WORD_UNION;

typedef union {
    INT32U dword;
    struct {
        INT16U low;
        INT16U high;
    } words;
    struct {
        INT8U addr0;  //low byte.
        INT8U addr1;
        INT8U addr2;
        INT8U addr3; //high byte.
    } bytes;    
}DWORD_UNION;

typedef struct {
    INT8U cmd;    
    INT8U len;
    INT8U msgidcrc;
    void (* entryproc)(void);
} EXECENTRY_ST;


#ifndef OFF
    #define OFF     0
#endif

#ifndef ON
    #define ON      1
#endif

#ifndef True
    #define True    1
#endif

#ifndef False
    #define False   0
#endif

#ifndef false
    #define false   0
#endif

#ifndef true
    #define true    1
#endif

#ifndef TRUE
    #define TRUE    1
#endif

#ifndef FALSE
    #define FALSE   0
#endif


#endif

